Skip to content

Add translations to times and numbers - #1223

Merged
jamiebenstead merged 10 commits into
translate-web-componentfrom
add-translations-to-times-and-numbers
Jul 7, 2025
Merged

Add translations to times and numbers#1223
jamiebenstead merged 10 commits into
translate-web-componentfrom
add-translations-to-times-and-numbers

Conversation

@jamiebenstead

Copy link
Copy Markdown
Contributor

@jamiebenstead
jamiebenstead temporarily deployed to previews/1223/merge June 27, 2025 10:19 — with GitHub Actions Inactive
@jamiebenstead
jamiebenstead temporarily deployed to previews/1223/merge June 27, 2025 10:35 — with GitHub Actions Inactive
@jamiebenstead
jamiebenstead temporarily deployed to previews/1223/merge June 27, 2025 13:49 — with GitHub Actions Inactive
@jamiebenstead
jamiebenstead temporarily deployed to previews/1223/merge June 27, 2025 14:17 — with GitHub Actions Inactive
@jamiebenstead
jamiebenstead temporarily deployed to previews/1223/merge June 27, 2025 14:38 — with GitHub Actions Inactive
@loiswells97
loiswells97 temporarily deployed to previews/1223/merge July 1, 2025 08:48 — with GitHub Actions Inactive
@loiswells97
loiswells97 temporarily deployed to previews/1223/merge July 1, 2025 09:16 — with GitHub Actions Inactive
@loiswells97
loiswells97 temporarily deployed to previews/1223/merge July 1, 2025 09:20 — with GitHub Actions Inactive
@@ -0,0 +1,16 @@
import { intlFormatDistance } from "date-fns";

const localeMap = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm lacking a bit of context here, but are we redefining this list, rather than using a shared source of truth?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the answer is that this map is for ensuring that our locales match up with the ones from the library

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we move this into a central location, maybe a separate util called localeMappings.js or something, and make sure nowhere else is redefining it?

Comment thread src/utils/formatRelativeTime.js Outdated
};

export const formatRelativeTime = (lastSavedTime, now, languageCode) => {
const locale = localeMap[languageCode] || localeMap.en; // Default to English if no match found;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this fallback logic be handled by react-i18next, is this duplicated logic?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm possibly - my preference would be if we can default to the i18n default where possible to avoid setting this in multiple places. But perhaps we need a fallback even then to avoid weird breakages if that was ever to change (it's purposely different in the tests for instance)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it's probably unlikely but it just feels a bit wrong to me that if the fallback language was changed across the app, this would still be falling back to en - at the very least we should be using a shared var for the fallback, that's also being used by react-i18next

Comment thread src/utils/formatRelativeTime.test.js
@jamiebenstead
jamiebenstead temporarily deployed to previews/1223/merge July 7, 2025 09:00 — with GitHub Actions Inactive
@jamiebenstead
jamiebenstead changed the base branch from main to translate-web-component July 7, 2025 09:34

@loiswells97 loiswells97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 👍

@jamiebenstead
jamiebenstead merged commit 014e63a into translate-web-component Jul 7, 2025
8 checks passed
@jamiebenstead
jamiebenstead deleted the add-translations-to-times-and-numbers branch July 7, 2025 09:41
@loiswells97 loiswells97 mentioned this pull request Sep 19, 2025
loiswells97 added a commit that referenced this pull request Sep 19, 2025
### Added

- Ability to translate demo project instructions (#1230)
- Translations (#1212)

### Changed

- Improved status bar styling (#1221)
- Added method to translate last saved time (#1223)
- Deleting unused strings and components (#1225)
- Determine locale from web component attribute instead of browser path
(#1244)

### Fixed

- CrowdIn issue for pluralised strings with no `one` version (#1234)
- Update `imagePanel.gallery` string to remove Title Casing for
consistency (#1238)
- Update `imageUploadButton.uploadImage` string to remove Title Casing
for consistency (#1238)
- Fixed typo in the `en.json` translation file (#1241)

### Removed

- Remove unused translation string `filePanel.images` (#1238)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants